//58.最后一个单词的长度
//https://leetcode.cn/problems/length-of-last-word/
class Solution {
public:
    int lengthOfLastWord(string s) {
        int n = s.size();
        int pos = n-1;
        while(s[pos] == ' ') --pos,--n;
        while(pos >= 0 && s[pos] != ' ') --pos;
        return pos == -1?n:n-pos-1;
    }
};